package com.atguigu.educms.service.impl;

import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.mapper.CrmBannerMapper;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author ct_start
 * @since 2021-08-18
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {



    // redis 里面的存储 结构是String类型  "banner:selectIndexList" 直接可以使用 get banner:selectIndexList 获取里面的值
    @Cacheable(key="'selectIndexList'",value = "banner") // 根据方法对其返回结果进行缓存,下次请求时如果缓存存在,则直接从缓存中读取数据;如果不存在,则执行方法将数据存放在缓存中

    @Override
    public List<CrmBanner> selectAllBanner() {
        // 根据id 值的大小进行降序排列
        QueryWrapper<CrmBanner>queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        // 再进行sql 语句的拼接
        queryWrapper.last("limit 2");

        List<CrmBanner> list = baseMapper.selectList(queryWrapper);
        return list;
    }

}
